package com.quyeying.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quyeying.annotation.PassToken;
import com.quyeying.entity.TblPopularizeVideoEntity;
import com.quyeying.entity.TblProductImageEntity;
import com.quyeying.service.TblPopularizeVideoService;
import com.quyeying.service.TblProductImageService;
import com.quyeying.utils.result.R;
import com.quyeying.utils.result.ResultEnum;
import com.quyeying.utils.result.ReturnPageData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Map;

/**
 * <p>
 * tbl_popularize_video 前端控制器
 * </p>
 *
 * @author skx
 * @since 2022-10-20
 */
@Slf4j
@RestController
@RequestMapping("popularizeVideoEntity")
public class TblPopularizeVideoController {

    @Resource
    private TblPopularizeVideoService tblPopularizeVideoService;

    /**
     * 分页查询
     **/
    @PassToken
    @GetMapping("/findListByPage")
    public R findListByPage(HttpServletRequest request, @RequestParam Integer current,
                            @RequestParam Integer size, Long merchantId) {
        try {
            String end = "user";
            return tblPopularizeVideoService.findListByPage(request, current, size, merchantId,end);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.error(ResultEnum.SYSTEM_ERROR);
        }
    }

    /**
     * id查询
     **/
    @PassToken
    @GetMapping("/findByVideoId")
    public R findById(HttpServletRequest request, Long id) {
        try {
            return tblPopularizeVideoService.findByVideoId(request, id);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.error(ResultEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 增加分享量
     **/
    @PostMapping("/updateShareNum")
    public R updateShareNum(@RequestBody TblPopularizeVideoEntity tblPopularizeVideoEntity) {
        try {
            return tblPopularizeVideoService.updateShareNum(tblPopularizeVideoEntity);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.error(ResultEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 随机视频列表
     */
    @PassToken
    @GetMapping("/randomVideoList")
    public R randomVideoList(HttpServletRequest request) {
        try {
            return tblPopularizeVideoService.randomVideoList(request);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.error(ResultEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 分页获取商品最新视频列表
     */
    @PassToken
    @GetMapping("/newVideoPage")
    public R newVideoPage(HttpServletRequest request, @RequestParam Integer current,
                          @RequestParam Integer size, Long vid) {
        try {
            Page<Map<String, Object>> mapPage = tblPopularizeVideoService.newVideos(request, new Page<>(current, size), vid);
            return R.success(ReturnPageData.fillingData(mapPage));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.error(ResultEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 增加视频浏览量
     */
    @PassToken
    @GetMapping("/addVideoBrowseNum")
    public R addVideoBrowseNum(HttpServletRequest request, Long videoId) {
        try {
            return tblPopularizeVideoService.addVideoBrowseNum(request, videoId);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.error(ResultEnum.SYSTEM_ERROR);
        }
    }
}
